#pragma once

#include  "iostream"
#include  "vector"
#include  "stack"
#include  "unordered_map"
#include   "queue"

using namespace std;


//todo 思路很简单 但是我剽窃了
unordered_map<int, int> mp;
vector<int> vec;

RandomizedSet() {
}

bool insert(int val) {
    auto iter = mp.find(val);
    if (iter != mp.end())
        return false;
    vec.push_back(val);
    mp[val] = vec.size() - 1;
    return true;
}

bool remove(int val) {
    auto iter = mp.find(val);
    if (iter == mp.end())
        return false;

    int index = iter->second;
    mp[vec.back()] = index;
    swap(vec[index], vec.back());
    vec.pop_back();
    mp.erase(val);
    return true;

}

int getRandom() {
    int randomIndex = rand() % vec.size();
    return vec[randomIndex];

}